package com.ccrfid.rmc6.repository.personnel;

import com.ccrfid.rmc6.entity.personnel.PersonnelPrisonerView;
import com.ccrfid.rmc6.repository.search.SearchableRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;

import java.util.List;

public interface PersonnelPrisonerViewRepository
        extends Repository<PersonnelPrisonerView, Long>, SearchableRepository<PersonnelPrisonerView> {

    PersonnelPrisonerView getById(Long id);

    PersonnelPrisonerView getByPersonnelSn(String personnelSn);

    PersonnelPrisonerView getByUnifoNo(String unifoNo);

    PersonnelPrisonerView getByUnifoNoAndPersonnelSnIsNull(String unifoNo);

    PersonnelPrisonerView getByCardNumber(Long cardNumber);

    Boolean existsByPersonnelSn(String personnelSn);

    Boolean existsByUnifoNo(String unifoNo);
    Boolean existsByUnifoNoAndPersonnelSnIsNull(String unifoNo);

    List<PersonnelPrisonerView> getByIsDeathPrisoner(Integer isDeathPrisoner);

    List<PersonnelPrisonerView> getByIsDeathPrisonerAndEnabled(Integer isDeathPrisoner, Integer enabled);

    List<PersonnelPrisonerView> getByIsDeathPrisonerAndEnabledAndLocatorAddress(Integer isDeathPrisoner, Integer enabled, Integer locatorAddress);

    List<PersonnelPrisonerView> getByIsMajorCriminalOffender(Integer isMajorCriminalOffender);

    List<PersonnelPrisonerView> getByIsMajorCriminalOffenderAndEnabled(Integer isMajorCriminalOffender, Integer enabled);

    List<PersonnelPrisonerView> getByIsMajorCriminalOffenderAndEnabledAndLocatorAddress(Integer isMajorCriminalOffender, Integer enabled, Integer locatorAddress);

    List<PersonnelPrisonerView> getByIsInfectedPrisoner(Integer isInfectedPrisoner);

    List<PersonnelPrisonerView> getByIsInfectedPrisonerAndEnabled(Integer isInfectedPrisoner, Integer enabled);

    List<PersonnelPrisonerView> getByIsInfectedPrisonerAndEnabledAndLocatorAddress(Integer isInfectedPrisoner, Integer enabled, Integer locatorAddress);

    List<PersonnelPrisonerView> getByIsFocusedPrisoner(Integer isFocusedPrisoner);

    List<PersonnelPrisonerView> getByIsFocusedPrisonerAndEnabled(Integer isFocusedPrisoner, Integer enabled);

    List<PersonnelPrisonerView> getByIsFocusedPrisonerAndEnabledAndLocatorAddress(Integer isFocusedPrisoner, Integer enabled, Integer locatorAddress);

    List<PersonnelPrisonerView> getByOrgId(Long orgId);

    List<PersonnelPrisonerView> getByOrgIdAndEnabled(Long orgId, Integer enabled);

    @Query("select v from PersonnelPrisonerView v where v.orgId = ?1 and v.enabled = 1" +
            "and (v.isDeathPrisoner = 1 or v.isFocusedPrisoner = 1 " +
            "or v.isInfectedPrisoner = 1 or v.isMajorCriminalOffender = 1)")
    List<PersonnelPrisonerView> getImportantPrisonersByOrgId(Long orgId);

    Long countByEnabledAndIsDeathPrisoner(Integer enabled, Integer isDeathPrisoner);
    Long countByEnabledAndIsDeathPrisonerAndOnlineStatus(Integer enabled, Integer isDeathPrisoner, Integer onlineStatus);
    Long countByEnabledAndIsMajorCriminalOffender(Integer enabled, Integer isMajorCriminalOffender);
    Long countByEnabledAndIsMajorCriminalOffenderAndOnlineStatus(Integer enabled, Integer isMajorCriminalOffender, Integer onlineStatus);
    Long countByEnabledAndIsFocusedPrisoner(Integer enabled, Integer isFocusedPrisoner);
    Long countByEnabledAndIsFocusedPrisonerAndOnlineStatus(Integer enabled, Integer isFocusedPrisoner, Integer onlineStatus);
    Long countByEnabledAndIsInfectedPrisoner(Integer enabled, Integer isInfectedPrisoner);
    Long countByEnabledAndIsInfectedPrisonerAndOnlineStatus(Integer enabled, Integer isInfectedPrisoner, Integer onlineStatus);

    int countByEnabled(int enabled);
    Long countByEnabledAndIsFocusedPrisonerAndOrgId(Integer enabled, Integer isFocusedPrisoner, Long orgId);

    Long countAllByEnabledAndIsFocusedPrisonerAndOrgIdIn(Integer enabled, Integer isFocusedPrisone,List<Long> orgIdList);

    int countAllByEnabledAndOrgId(int enable,Long orgId);
}
